<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;

class StudentSignModel extends BaseModel
{
    use HasFactory;
    protected $table = 'student_sign';
    protected $fillable = [
        'company_id',
        'student_id',
        'arrange_id',
        'course_id',
        'class_id',
        'student_course_id',
        'date',
        'time',
        'result',
        'course_num',
        'course_money',
        'commission'
    ];

    private const SIGN_RESULT = [ '未签到', '正常', '迟到', '请假', '旷课' ];
    public static function courseSigns($studentId, $courseId) {
        $signs = self::where('student_id', $studentId)
            ->where('course_id', $courseId)
            ->orderBy('id', 'desc')
            ->get();
        if ($signs) {
            foreach ($signs as $sign) {
                $sign->result_name = self::SIGN_RESULT[$sign->result];
            }
        }
        return $signs;
    }
}
